// pages/homedetail/homedetail.js
import {
  getteachers,
  courseslist
} from '../../api/index'
import {
  get
} from '../../utils/http'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: "",
    name: "",
    tabbar: [{
      id: 0,
      text: '今日课程',
    }, {
      id: 1,
      text: '其他课程',
    }],
    currentTab: 0,
    detail: [],
    course: [],
    Page: {
      page: 1,
      psize: 5
    }
  },
  // 点击切换
  switchNav: function (e) {
    console.log(e);
    var that = this;
    if (this.data.currentTab == e.currentTarget.dataset.index) {
      return false;
    } else {
      that.setData({
        currentTab: e.currentTarget.dataset.index
      });
    }
  },
  // 滑动切换
  bindChange: function (e) {
    // console.log(e)
    var that = this;
    that.setData({
      currentTab: e.detail.current
    });
  },
  async getdetail() {
    const res = await get(getteachers, {
      id: this.data.id
    })
    console.log(res);
    if (res.errCode == '10000') {
      this.setData({
        detail: res.data
      })
    }
  },
  async getcourseslist() {
    const res = await get(courseslist, {
      page: this.data.Page.page,
      psize: this.data.Page.psize,
    })
    console.log(res, 123);
    if (res.errCode == '10000') {
      this.setData({
        course: res.data.list
      })
    }
  },
  make(e) {
    let id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/course/course?id=' + id,
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options);
    this.setData({
      id: options.id,
      name: options.name
    })
    this.getdetail()
    this.getcourseslist()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    wx.setNavigationBarTitle({
      title: this.data.name,
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})